home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectShow / Editing / DexterVB / QuartzHelper.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-10-08  |  15.0 KB  |  337 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "VBQuartzHelper"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. '*******************************************************************************
  15. '*       This is a part of the Microsoft DXSDK Code Samples.
  16. '*       Copyright (C) 1999-2001 Microsoft Corporation.
  17. '*       All rights reserved.
  18. '*       This source code is only intended as a supplement to
  19. '*       Microsoft Development Tools and/or SDK documentation.
  20. '*       See these sources for detailed information regarding the
  21. '*       Microsoft samples programs.
  22. '*******************************************************************************
  23. Option Explicit
  24. Option Base 0
  25. Option Compare Text
  26.  
  27. 'IMediaControl is used for async rendering & control;
  28. 'It is a derivitive interface of the FilterGraph Manager.
  29. Private m_objFilterGraphManager As IMediaControl
  30.  
  31.  
  32. ' **************************************************************************************************************************************
  33. ' * PUBLIC INTERFACE- ENUMERATIONS
  34. ' *
  35. ' *
  36.             Public Enum QTZSynchronicityConstants
  37.             QTZSynchronous = 0   'Synchronous execution
  38.             QTZAsynchronous = 1 'Asynchronous execution
  39.             End Enum
  40.             
  41.             Public Enum QTZStatusConstants
  42.             QTZStatusStopped = 0 'State Stopped
  43.             QTZStatusPaused = 1  'State Paused
  44.             QTZStatusPlaying = 2  'State Playing
  45.             End Enum
  46.  
  47.  
  48. ' **************************************************************************************************************************************
  49. ' * PUBLIC INTERFACE- PROPERTIES
  50. ' *
  51. ' *
  52.             ' ******************************************************************************************************************************
  53.             ' * procedure name: FilterGraph
  54.             ' * procedure description: Allows the client to get the encapsulated graph as a FilterGraph object
  55.             ' *
  56.             ' ******************************************************************************************************************************
  57.             Public Property Get FilterGraph() As FilgraphManager
  58. Attribute FilterGraph.VB_UserMemId = 0
  59. Attribute FilterGraph.VB_MemberFlags = "200"
  60.             On Local Error GoTo ErrLine
  61.             If Not m_objFilterGraphManager Is Nothing Then
  62.                Set FilterGraph = m_objFilterGraphManager
  63.             End If
  64.             Exit Property
  65.             
  66. ErrLine:
  67.             Err.Clear
  68.             Exit Property
  69.             End Property
  70.             
  71.             
  72.             
  73.             ' ******************************************************************************************************************************
  74.             ' * procedure name: FilterGraph
  75.             ' * procedure description: Allows the client to set a constructed FilterGraph object for which to render and control.
  76.             ' *
  77.             ' ******************************************************************************************************************************
  78.             Public Property Set FilterGraph(RHS As FilgraphManager)
  79.             On Local Error GoTo ErrLine
  80.             If Not RHS Is Nothing Then
  81.                Set m_objFilterGraphManager = RHS
  82.             End If
  83.             Exit Property
  84.             
  85. ErrLine:
  86.             Err.Clear
  87.             Exit Property
  88.             End Property
  89.             
  90.             
  91.             
  92.             ' ******************************************************************************************************************************
  93.             ' * procedure name: Position
  94.             ' * procedure description: Allows the client to get the current position within the context of the media.
  95.             ' *
  96.             ' ******************************************************************************************************************************
  97.             Public Property Get Position() As Double
  98.             Dim objPosition As IMediaPosition
  99.             On Local Error GoTo ErrLine
  100.             If Not m_objFilterGraphManager Is Nothing Then
  101.                'derive the position control interface
  102.                Set objPosition = m_objFilterGraphManager
  103.                'set the current position using this interface
  104.                Position = CDbl(objPosition.CurrentPosition)
  105.             End If
  106.             Exit Property
  107.             
  108. ErrLine:
  109.             Err.Clear
  110.             Exit Property
  111.             End Property
  112.             
  113.             
  114.             ' ******************************************************************************************************************************
  115.             ' * procedure name: Position
  116.             ' * procedure description: Allows the client to set the current position within the context of the media.
  117.             ' *
  118.             ' ******************************************************************************************************************************
  119.             Public Property Let Position(RHS As Double)
  120.             Dim objPosition As IMediaPosition
  121.             On Local Error GoTo ErrLine
  122.             If Not m_objFilterGraphManager Is Nothing Then
  123.                'derive the position control interface
  124.                Set objPosition = m_objFilterGraphManager
  125.                'set the current position using this interface
  126.                objPosition.CurrentPosition = RHS
  127.             End If
  128.             Exit Property
  129.             
  130. ErrLine:
  131.             Err.Clear
  132.             Exit Property
  133.             End Property
  134.             
  135.             
  136.             ' ******************************************************************************************************************************
  137.             ' * procedure name: Position
  138.             ' * procedure description: Allows the client to get the current state of the playback.
  139.             ' *
  140.             ' ******************************************************************************************************************************
  141.             Public Property Get State(Optional Timeout As Long = 1000) As QTZStatusConstants
  142.             Dim nResultant As Long
  143.             Dim objControl As IMediaControl
  144.             On Local Error GoTo ErrLine
  145.             If Not m_objFilterGraphManager Is Nothing Then
  146.                'derive the position control interface
  147.                Set objControl = m_objFilterGraphManager
  148.                'get the current state using this interface
  149.                Call objControl.GetState(Timeout, nResultant)
  150.                'return to client
  151.                State = nResultant
  152.             End If
  153.             Exit Property
  154.             
  155. ErrLine:
  156.             Err.Clear
  157.             Exit Property
  158.             End Property
  159.            
  160.             
  161.             
  162.             ' ******************************************************************************************************************************
  163.             ' * procedure name: Duration
  164.             ' * procedure description: Allows the client to get the media's duration.
  165.             ' *
  166.             ' ******************************************************************************************************************************
  167.             Public Property Get Duration() As Double
  168.             Dim objPosition As IMediaPosition
  169.             On Local Error GoTo ErrLine
  170.             If Not m_objFilterGraphManager Is Nothing Then
  171.                Set objPosition = m_objFilterGraphManager
  172.                Duration = CDbl(objPosition.Duration)
  173.             End If
  174.             Exit Property
  175.             
  176. ErrLine:
  177.             Err.Clear
  178.             Exit Property
  179.             End Property
  180.             
  181.             
  182.             ' ******************************************************************************************************************************
  183.             ' * procedure name: FPS
  184.             ' * procedure description: Allows the client to get the media's playback rate, in frames per second.
  185.             ' *
  186.             ' ******************************************************************************************************************************
  187.             Public Property Get FPS() As Double
  188.             Dim objPosition As IMediaPosition
  189.             On Local Error GoTo ErrLine
  190.             If Not m_objFilterGraphManager Is Nothing Then
  191.                Set objPosition = m_objFilterGraphManager
  192.                FPS = CDbl(objPosition.Rate)
  193.             End If
  194.             Exit Property
  195.             
  196. ErrLine:
  197.             Err.Clear
  198.             Exit Property
  199.             End Property
  200.             
  201.             
  202.             ' ******************************************************************************************************************************
  203.             ' * procedure name: StopTime
  204.             ' * procedure description: Allows the client to get the media's StopTime (when the media will hault playback)
  205.             ' *
  206.             ' ******************************************************************************************************************************
  207.             Public Property Get StopTime() As Double
  208.             Dim objPosition As IMediaPosition
  209.             On Local Error GoTo ErrLine
  210.             If Not m_objFilterGraphManager Is Nothing Then
  211.                Set objPosition = m_objFilterGraphManager
  212.                StopTime = CDbl(objPosition.StopTime)
  213.             End If
  214.             Exit Property
  215.             
  216. ErrLine:
  217.             Err.Clear
  218.             Exit Property
  219.             End Property
  220.  
  221.  
  222. ' **************************************************************************************************************************************
  223. ' * PUBLIC INTERFACE- METHODS
  224. ' *
  225. ' *
  226.             ' ******************************************************************************************************************************
  227.             ' * procedure name: StopGraph
  228.             ' * procedure description: Stop the rendering/playback of the graph.
  229.             ' *
  230.             ' ******************************************************************************************************************************
  231.             Public Sub StopGraph()
  232.             On Local Error GoTo ErrLine
  233.             If Not m_objFilterGraphManager Is Nothing Then
  234.               Call m_objFilterGraphManager.Stop
  235.             End If
  236.             Exit Sub
  237.             
  238. ErrLine:
  239.             Err.Clear
  240.             Exit Sub
  241.             End Sub
  242.             
  243.             
  244.             ' ******************************************************************************************************************************
  245.             ' * procedure name: PauseGraph
  246.             ' * procedure description: Pauses the rendering/playback of the graph.
  247.             ' *
  248.             ' ******************************************************************************************************************************
  249.             Public Sub PauseGraph()
  250.             On Local Error GoTo ErrLine
  251.             If Not m_objFilterGraphManager Is Nothing Then
  252.                Call m_objFilterGraphManager.Pause
  253.             End If
  254.             Exit Sub
  255.             
  256. ErrLine:
  257.             Err.Clear
  258.             Exit Sub
  259.             End Sub
  260.             
  261.             
  262.             ' ******************************************************************************************************************************
  263.             ' * procedure name: RunGraph
  264.             ' * procedure description:   Renders the graph.
  265.             ' *
  266.             ' ******************************************************************************************************************************
  267.             Public Sub RunGraph(Optional Synchronicity As QTZSynchronicityConstants = QTZAsynchronous)
  268.             Dim objPosition As IMediaPosition
  269.             Dim objControl As IMediaControl
  270.             On Local Error GoTo ErrLine
  271.             
  272.             If Not m_objFilterGraphManager Is Nothing Then
  273.                Select Case Synchronicity
  274.                        Case QTZSynchronicityConstants.QTZSynchronous
  275.                                 'run the graph
  276.                                 Call m_objFilterGraphManager.Run
  277.                                 'obtain the position of audio/video
  278.                                 Set objPosition = m_objFilterGraphManager
  279.                                 'loop with events
  280.                                 Do: DoEvents
  281.                                         If objPosition.CurrentPosition = objPosition.StopTime Then
  282.                                            Call m_objFilterGraphManager.Stop
  283.                                            Exit Do
  284.                                         End If
  285.                                 Loop
  286.                     
  287.                         Case QTZSynchronicityConstants.QTZAsynchronous
  288.                                 'the client desires to run the graph asynchronously
  289.                                 Call m_objFilterGraphManager.Run
  290.                 End Select
  291.             End If
  292.             'clean-up & dereference
  293.             If Not objPosition Is Nothing Then Set objPosition = Nothing
  294.             Exit Sub
  295.             
  296. ErrLine:
  297.             Err.Clear
  298.             Exit Sub
  299.             End Sub
  300.  
  301.  
  302.  
  303. ' **************************************************************************************************************************************
  304. ' * PUBLIC INTERFACE- METHODS
  305. ' *
  306. ' *
  307.             ' ******************************************************************************************************************************
  308.             ' * procedure name: Class_Initialize
  309.             ' * procedure description: fired intrinsically by visual basic, occurs when this class initalizes
  310.             ' *
  311.             ' ******************************************************************************************************************************
  312.             Private Sub Class_Initialize()
  313.             On Local Error GoTo ErrLine
  314.             Set m_objFilterGraphManager = New FilgraphManager
  315.             Exit Sub
  316.             
  317. ErrLine:
  318.             Err.Clear
  319.             Exit Sub
  320.             End Sub
  321.             
  322.             
  323.             ' ******************************************************************************************************************************
  324.             ' * procedure name: Class_Terminate
  325.             ' * procedure description: fired intrinsically by visual basic, occurs when this class terminates
  326.             ' *
  327.             ' ******************************************************************************************************************************
  328.             Private Sub Class_Terminate()
  329.             On Local Error GoTo ErrLine
  330.             If Not m_objFilterGraphManager Is Nothing Then Set m_objFilterGraphManager = Nothing
  331.             Exit Sub
  332.             
  333. ErrLine:
  334.             Err.Clear
  335.             Exit Sub
  336.             End Sub
  337.